import java.util.Scanner;

public class MaxSum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int arr[] = new int[N];
        for (int i = 0; i < N; i++) {

            arr[i] = sc.nextInt();
        }
        int max = maxSum(arr, 0, N - 1);
        System.out.println("最大子数组和为 " + max);
    }

    public static int maxSum(int arr[], int left, int right) {

        if (left == right) {
            return arr[left] > 0 ? arr[left] : 0;
        }


        int center = (left + right) / 2;
        int leftSum = maxSum(arr, left, center);
        int rightSum = maxSum(arr, center + 1, right);


        int crossSum = maxCrossingSum(arr, left, center, right);


        return Math.max(leftSum, Math.max(rightSum, crossSum));
    }


    private static int maxCrossingSum(int arr[], int left, int center, int right) {
        int sum = 0;
        int left_sum = Integer.MIN_VALUE;




        for (int i = center; i >= left; i--) {
            sum = sum + arr[i];
            if (sum > left_sum) {
                left_sum = sum;
            }
        }

        sum = 0;
        int right_sum = Integer.MIN_VALUE;


        for (int j = center + 1; j <= right; j++) {
            sum = sum + arr[j];
            if (sum > right_sum) {
                right_sum = sum;
            }
        }


        return left_sum + right_sum;
    }
}